<?php
		$result = array();
		if (isset($_FILES['Filedata']) )
		{
			$file = $_FILES['Filedata']['tmp_name'];
			$error = false;
			$size = false;
			$toFile = dirname(__FILE__).'/../Upload/ZS/'.$_FILES['Filedata']['name'];
			if( move_uploaded_file( $file, $toFile ) ){
				@chmod( $toFile, 0755 );		
			}else{
				//$error = "0";
				$result['result'] = '0';
			}
		
			$addr = gethostbyaddr($_SERVER['REMOTE_ADDR']);
		
			$log = fopen('script.log', 'a');
			fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . preg_replace('/^[^.]+/', '***', $addr) . ": {$_FILES['Filedata']['name']} - {$_FILES['Filedata']['size']} byte\n" );
			fclose($log);
		
			if ($error)
			{
				$result['result'] = '0';
				$result['error'] = $error;
			}
			else
			{
				$result['result'] = '1';
				//$result['size'] = "Uploaded an image ({$size['mime']}) with  {$size[0]}px/{$size[1]}px.";
				$result['size'] = "Uploaded an file ok.";
			}
		
		}
		else
		{
			$result['result'] = '0';
			$result['error'] = 'Missing file or internal error!';
		}
		
		if (!headers_sent() )
		{
			header('Content-type: application/json');
		}
		
		//echo json_encode($result);
		echo $result['result'];
		exit;